﻿using System;
using System.Runtime.Serialization;
using NCMIS.ObjectModel.MetaData;
using System.Collections.Generic;

namespace NCMIS.ObjectModel
{
    /// <summary>
    /// Utility class. Represents a list of PathedCmisObjects. Used in e.g. GetChildren() in
    /// NavigationService.
    /// </summary>
    [DataContract(Namespace = CmisNs.Cmism)]
    public class PathedCmisObjectList
    {
        [DataMember(Name = "objects")]
        public PathedCmisObject[] Objects
        {
            get;
            set;
        }

        [DataMember(Name = "hasMoreItems")]
        public bool HasMoreItems
        {
            get;
            set;
        }

        [DataMember(Name = "numItems")]
        public string NumItems
        {
            get;
            set;
        }

        public void Remove(string objectId)
        {
            List<PathedCmisObject> list = new List<PathedCmisObject>();
            foreach (PathedCmisObject obj in Objects)
            {
                CmisObject cmisObject = obj.Object;
                string currentObjectId = cmisObject.Properties.ObjectId.SingleValue;
                if (currentObjectId != objectId)
                {
                    list.Add(obj);
                }
            }
            Objects = list.ToArray();
        }
    }
}
